<template>
	<view class="pages">
		
		<!-- <view class="tabs-content"> -->
			<u-tabs :list="typelist" :show-bar="false" :is-scroll="false" :current="current"
				@change="change"></u-tabs>
		<!-- </view> -->
		<view class="voucher-list box-content">
			<view class="item-voucher" v-for="(item,index) in list" :key="index">
				<view class="left-info">
					<view class="title">足浴按摩 <text class="price">{{item.reduction_price}}元</text><text>代金券</text></view>
					<view class="man-txt">满{{item.use_price}}使用</view>
					<view class="man-txt flex_r_between" style="font-size: 20rpx;">
							<text>该代金券仅限应用内使用</text>
							<i>{{item.rule_name}}</i>
					</view>
				</view>
				<view class="right-info">
					<view class="price"><text>￥</text>{{item.reduction_price}} </view>
					<view :class="item.is_receive?'choose-btn':'choose-btn use'" @click="item.is_receive?draw(item,index):link()">{{item.is_receive?'立即领取':'去使用'}}</view>
				</view>
				<image class="fixed-use" v-if="current == 1" src="https://qiniu-cdn.maeiyun.com/imgs/mine/b2.png" mode=""></image>
			</view>
		</view>
		<blankPage img="https://qiniu-cdn.maeiyun.com/imgs/blank/no_order.png" text="暂无数据" :width="161"
			:height="129" v-show="list.length <1"></blankPage>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				list:[],
				type:0,//选择  1展示,
				page:1,
				page1:1,
				typelist: [{
					name: '待领取',
					id: 0
				}, {
					name: '已领取',
					id: 1
				}],
				current:0
			}
		},
		onLoad(option) {
			this.getVoucherList()
	
		},
		onReachBottom() {
			this.getVoucherList()
		},
		methods:{
			change(e){
				this.current = e
				this.page = 1
				this.list = []
				if(this.current == 0){
					this.getVoucherList()
				}else{
					this.getGainVoucherList()
				}
			},
			getVoucherList(){
				let that = this
				this.request.httpTokenRequest({
					url: "ticket/canReceiveTicket",
					method: "get"
				}, {
					page:this.page
				}).then(res => {
					if (res.code == 0) {
						res.data.data.map(item=>{
							if(item.is_receive){
								that.list.push(item)
							}
						})
						that.page++
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			getGainVoucherList(){
				let that = this
				this.request.httpTokenRequest({
					url: "ticket/myTicket",
					method: "get"
				}, {
					page:this.page
				}).then(res => {
					if (res.code == 0) {
						that.page++
						that.list = [...that.list,...res.data.data]
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			chooseVoucher(item){
				// publicData.selectiveTiket = item
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				// #ifdef APP
					prevPage.$vm.voucher = item
				// #endif
				// #ifndef APP
					prevPage.voucher = item
				// #endif
				uni.navigateBack({})
			},
			link(){
				uni.navigateTo({
					url:'/otherpages/massage/massageIndex'
				})
			},
			draw(item,index){
				let that = this
				this.request.httpTokenRequest({
					url: "ticket/receiveTicket",
					method: "post"
				}, {
					rule_id: item.rule_id,
					rft_id: item.rft_id,
					ticket_id: item.ticket_id
				}).then(res => {
					if (res.code == 0) {
						// item.is_receive = true
						that.list[index].is_receive = false
						that.$util.msg(res.msg)
					} else {
						that.$util.msg(res.msg)
						return
					}
				}, error => {})
			}
		}
	}
</script>

<style lang="scss">
	.pages{
		// padding-top: calc(var(--status-bar-height) + 10px);
	}
	.tabs-content{
		height: calc(var(--status-bar-height) + 10px);
		background-color: '#F5F7F8';
	}
	.voucher-list{
		padding:0 30rpx;
	}
	.item-voucher{
		background: url('https://qiniu-cdn.maeiyun.com/imgs/mine/b1.png')no-repeat;
		background-size: 100% 100%;
		height: 160rpx;
		display: flex;
		align-items: center;
		margin-top: 20rpx;
		position: relative;
		.fixed-use{
			width: 121rpx;
			height: 90rpx;
			position: absolute;
			bottom: 35rpx;
			right: 210rpx;
		}
		.left-info{
			padding-left: 42rpx;
			flex: 1;
			.title{
				font-size: 30rpx;
				font-weight: 400;
				color: #525252;
				line-height: 42rpx;
				display: flex;
				align-items: center;
				.price{
					color: #D84A4C;
					font-size: 30rpx;
					margin-left: 30rpx;
				}
			}
			.man-txt{
				font-size: $uni-font-size-sm;
				font-weight: 400;
				color: #A8A8A8;
				line-height: 28rpx;
				margin-top: 10rpx;
				max-width: 90%;
				i {
					font-style: normal;
				}
			}
			.time{
				font-size: 20rpx;
				font-family: MaoKenTangYuan, MaoKenTangYuan;
				font-weight: normal;
				color: #FFFFFF;
			}
		}
		.right-info{
			margin-left: auto;
			margin-right: 23rpx;
			text-align: center;
			.price{
				font-size: 40rpx;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 56rpx;
				text{
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
			.choose-btn{
				width: 116rpx;
				height: 40rpx;
				background: rgba(255,255,255,0.64);
				border-radius: 25rpx;
				border: 3rpx solid rgba(255,255,255,0.33);
				font-size: $uni-font-size-sm;
				font-weight: 400;
				color: #9E2527;
				text-align: center;
				line-height: 40rpx;
			}
			.use{
				background: rgba(255,255,255,0.9)
			}
		}
	}
</style>